<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<link rel="stylesheet" href="../../layui/css/layui.css">
<script type="text/javascript" src="../../layui/layui.js" charset="utf-8"></script>
<link href="favicon.ico" rel="shortcut icon">
<head>
<meta charset="UTF-8">
<title>督查类型</title>
</head>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>
 
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="getCheckData">添加</button>
  </div>
</script>
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="zizeng">
    {{d.LAY_TABLE_INDEX+1}}
</script>              
<script>
layui.use(['table','form'], function(){
  var table = layui.table;
  var form = layui.form;
  table.render({
    elem: '#test'
    ,url:'list'
    ,height: 'full-20'
    ,cellMinWidth: 80
    ,toolbar: '#toolbarDemo'
    ,title: '督查类型表'
    ,even:true //开启隔行换色
    ,cols: [
    	[
      {type: 'checkbox', fixed: 'left'}
      ,{field:'zizeng', width:80, title: '序号',fixed: 'left',templet:'#zizeng'}
      ,{field:'sname', title:'督查类型', edit: 'text'}
      ,{field:'sdescribe', title:'督查类型描述', edit: 'text', sort: true}
      ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
    ]
    	]
    ,page: true
  });
  
  //头工具栏事件
  table.on('toolbar(test)', function(obj){
	  var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	      case 'getCheckData':
	    	  layer.open({
	  			type:1,
	  			title:'添加督查类型',
	  			area:'600px',
	  			anim: 1,
	  			skin: 'layui-layer-molv',
	  			content:layui.$('#add')
	    	  })
	      break;
	    };
	  });
  
  //监听行工具事件
  table.on('tool(test)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
    	layer.confirm('是否删除数据',{icon:3,title:"确认"}, function(index){
    	  layui.$.ajax({
              url:"deleteSupervisionType",
              type:"POST",
              data:{"sid":data.sid},
              dataType: "json",                
              success: function(data){            
	              if(data.sid==null){    
	            	  layer.msg("删除失败", {icon: 5});              
	              }else{
	                  layer.msg(data.id);
	                  obj.del();//删除这一行
	                  layer.close(index);//关闭弹框
	                  layer.msg("删除成功", {icon: 6}); 
	              	}
              },
              error:function(){
            	  window.location.reload();
              },
    	  });
      });
    } else if(obj.event === 'edit'){
    	form.val("formTest",data);
    	layer.open({
  			type:1,
  			title:'修改督查类型',
  			area:'600px',
  			anim: 1,
  			skin: 'layui-layer-molv',
  			content:layui.$('#update')
    	  });
    }
  });
});
</script>

<!------------------------------------------ 添加 ------------------------------------------------------->
<form id="add" class="layui-form" action="addSupervisionType" lay-filter="formTest" method="post" hidden="true" style="height:400px">
  <div class="layui-form-item">
    <label class="layui-form-label">督查类型</label>
    <div class="layui-input-block">
      <input type="text" name="sname" lay-verify="title" autocomplete="off" placeholder="请输入督查类型" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">类型描述</label>
    <div class="layui-input-block">
      <input type="text" name="sdescribe" placeholder="请输入督查类型描述" autocomplete="off" class="layui-input">
    </div>
  </div>
  
    <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
<!------------------------------------------ 修改 ------------------------------------------------------->
<form id="update" class="layui-form" action="updateSupervisionType" lay-filter="formTest" method="post" hidden="true" style="height:400px">
  
  <input type="hidden" name="sid" lay-verify="title" autocomplete="off" class="layui-input">
  
  <div class="layui-form-item">
    <label class="layui-form-label">督查类型</label>
    <div class="layui-input-block">
      <input type="text" name="sname" lay-verify="title" autocomplete="off" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">类型描述</label>
    <div class="layui-input-block">
      <input type="text" name="sdescribe" autocomplete="off" class="layui-input">
    </div>
  </div>
  
    <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

</body>
</html>